/*
 * @Descripttion: 
 * @version: 
 * @Author: zero
 * @Date: 2020-04-28 11:40:14
 * @LastEditors: zero
 * @LastEditTime: 2020-04-29 14:05:11
 */
import { history } from 'umi';

import { RequestConfig } from 'umi';
import config from "@/config"
import errorHandler  from "@/util/errorHandle"
export const request: RequestConfig = {
  prefix: process.env.NODE_ENV === "production" ? config.baseurl :'api/',
  credentials: 'include',
  errorHandler,
  // 自定义端口规范
  errorConfig: {
    adaptor: res => {
      return {
        success: res.code ==config.successCode,
        data:res.data,
        errorCode:res.code,
        errorMessage: res.msg,
      };
    },
  },
  middlewares: [],
};
export function onRouteChange({ matchedRoutes }) {
  history.block((location, action) => {
    // console.log(location, action)
    // // return false
    // return true
    // The location and action arguments indicate the location
    // we're transitioning to and how we're getting there.

    // A common use case is to prevent the user from leaving the
    // page if there's a form they haven't submitted yet.
    // if (input.value !== '') return 'Are you sure you want to leave this page?';
  });
}